from colorama import Fore,Back,Style,init
import platform
if platform.system()=="Windows":
    init()
class Test:
    def __init__(self):
        self.success=True
        self.ops=[]
    def print_entry(self,entry):
        print(Fore.YELLOW+entry[0]+" "+(Fore.RED if not entry[1] else Fore.GREEN)
              +("Succeed" if entry[1] else "Failed")+Fore.RESET)
    def ensure(self,boolop:bool,name:str|None=None):
        self.success=self.success and boolop
        self.ops.append(((f"Test Case #{len(self.ops)+1}" if (name is None) else name),
                         (1 if boolop else 0)))
        self.print_entry(self.ops[-1])
        return self.success
    def reset(self):
        self.success=True
        self.ops.clear()
    def print_report(self):
        if len(self.ops)==0:
            print(Fore.CYAN+"No test case tested."+Fore.RESET)
            return False
        print(Fore.CYAN+f"Tested {len(self.ops)} cases"+Fore.RESET)
        for i in self.ops:
            self.print_entry(i)
        print(Fore.CYAN+f"Result"+(Fore.RED if not self.success else Fore.GREEN)+" "+
              ("Failed" if not self.success else "Succeed")+Fore.RESET)
        return self.success
    